import { _decorator, Component, Node, Label, Sprite, SpriteAtlas, resources, Enum, assetManager, director } from 'cc';
import Banner from '../../Banner';

const { ccclass, property } = _decorator;

@ccclass
export default class HealthAdvicePanel extends Component {

    ageLimitAtalsPath: string = `Sprites/Common/AgeLimit`;

    onLoad() {
        this.node.getChildByName(`TitleLabel`).active = !Banner.IS_ANDROID;
        this.node.getChildByName(`ContentLabel`).active = !Banner.IS_ANDROID;
        this.node.getChildByName(`CompanyLb`).active = !Banner.IS_ANDROID;
        this.node.getChildByName(`LicenseLb`).active = !Banner.IS_ANDROID;
        this.node.getChildByName(`AgeLimitSp`).active = !Banner.IS_ANDROID;
        this.node.getChildByName(`LoadingLabel`).active = Banner.IS_ANDROID;

        if (Banner.IS_ANDROID) return;

        this.node.getChildByName(`CompanyLb`).getComponent(Label).string = `${Banner.Owner}`;
        this.node.getChildByName(`LicenseLb`).getComponent(Label).string = `${Banner.License}`;

        //适龄提示角标
        let ageLimitSp: Sprite = this.node.getChildByName(`AgeLimitSp`).getComponent(Sprite);
        switch (Banner.AgeLimit) {
            case 8:
                resources.load(this.ageLimitAtalsPath, SpriteAtlas, (err, res: SpriteAtlas) => {
                    ageLimitSp.spriteFrame = res.getSpriteFrame(`8`);
                });
                break;
            case 12:
                resources.load(this.ageLimitAtalsPath, SpriteAtlas, (err, res: SpriteAtlas) => {
                    ageLimitSp.spriteFrame = res.getSpriteFrame(`12`);
                });
                break;
            case 16:
                resources.load(this.ageLimitAtalsPath, SpriteAtlas, (err, res: SpriteAtlas) => {
                    ageLimitSp.spriteFrame = res.getSpriteFrame(`16`);
                });
                break;

            default:
                resources.load(this.ageLimitAtalsPath, SpriteAtlas, (err, res: SpriteAtlas) => {
                    ageLimitSp.spriteFrame = res.getSpriteFrame(`16`);
                });
                break;
        }
    }
}